var url = urls();
//lawyer
$.ajax({
    type: "post",
    url: url + "/api/lawyer/lawyer_list",
    data: {},
    dataType: "json",
    success: function (res) {
        lawyer_list(res);
        var swiper2 = new Swiper('.team_list .swiper-container', {
            prevButton: '.swiper-button-prev',
            nextButton: '.swiper-button-next',
            slidesPerView: 4,
            paginationClickable: true,
            spaceBetween: 40,
            loop: true,
            autoplay: 0,
            speed: 1000,
        });
    }
});

//团队
function lawyer_list(res) {
    var arr = res.data;
    var a = ''
    for (i in arr) {
        var position = arr[i].position || "";
        var describe_three = arr[i].describe_three || "";
        a += '<div class="swiper-slide team_introduce"><img class="head" src="' + url + '/upload/' + arr[i].portrait + '" /><div class="name"><span>' + arr[i].user_name + '</span><span>' + position + '</span></div><div class="content"><p>' + arr[i].describe + '</p><p>' + arr[i].describe_two + '</p><p>' + describe_three + '</p></div><a class="team_homepage" href="' + url + '/portal/index/lawyerdetails.html?id=lawyer_' + arr[i].id + '">查看主页</a><a class="team_consultation" href="javascript:;" onclick="show_wx();">立即咨询</a></div>';
    }
    $(".swiper-wrapper", ".team_list").html(a);
}
// <div class="company">' + arr[i].address + '</div>
//list
$.ajax({
    type: "post",
    url: url + "/api/case/case_list",
    data: {
        number: 3,
    },
    dataType: "json",
    success: function (res) {
        anli_details(res);
    }
});
//案例
function anli_details(val) {
    var arr = val.data.data;
    var a = ""
    for (i in arr) {
        a += '<div class="list" id="anli_' + arr[i].id + '"><img src="' + url + '/upload/' + arr[i].thumbnail + '" /><div class="list_txt_box"><a class="list_title" href="' + url + '/portal/index/anlidetails.html?id=anli_' + arr[i].id + '">' + arr[i].post_title + '</a><p class="list_txt">' + arr[i].post_excerpt + '</p><a class="list_to_details" href="' + url + '/portal/index/anlidetails.html?id=anli_' + arr[i].id + '">查看详情&nbsp;&gt;</a></div></div>';
    }
    $(".list_box").html(a);
    for (var i = 0; i < $(".list_txt").length; i++) {
        $(".list_txt").eq(i).html($(".list_txt").eq(i).html().substr(0, 100) + "...");
    }

    $(".list").click(function (e) {
        if (e.target.tagName == "IMG") {
            window.location.href = url + "/portal/index/anlidetails.html?id=" + this.id;
        }
    })
}

$(function () {
    $('.select').select2({
        width: "300px",
    });
    //查看更多
    $(".list_more").click(function () {
        window.location.href = url + "/portal/index/anli.html";
    })

    //轮播图1
    var swiper1 = new Swiper('.banner .swiper-container', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        loop: true,
        autoplay: 2000
    });

    //咨询
    var from_flag = true;
    $(".from_btn").click(function () {
        if (from_flag === true) {
            var select = $("select[name='select']", ".from").val();
            var tel = $("input[name='tel']", ".from").val();
            var name = $("input[name='name']", ".from").val();

            if (select == null) {
                layer.msg("请选择您要咨询的问题！", {
                    time: 2000
                });
                return;
            }
            if (tel == "") {
                layer.msg("请输入您的电话！", {
                    time: 2000
                });
                return;
            } else if (!(/^1[3456789]\d{9}$/.test(tel))) {
                layer.msg("请检查您输入的电话！", {
                    time: 2000
                });
                return;
            }
            if (name == '') {
                layer.msg("请输入您的姓名！", {
                    time: 2000
                });
                return;
            } else if (!(/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/.test(name))) {
                layer.msg("请检查您输入的姓名！", {
                    time: 2000
                });
                return;
            }
            if (select != null && (/^1[3456789]\d{9}$/.test(tel)) && (/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/.test(name))) {
                var question_url = document.URL;
                from_flag = false;
                $(this).attr("disabled", true);
                $.ajax({
                    type: "post",
                    url: url + "/api/question/problem_commit",
                    data: {
                        nick: name,
                        phone: tel,
                        content: select,
                        url: question_url
                    },
                    dataType: "json",
                    success: function (res) {
                        if (res.code == "1") {
                            layer.msg("提交成功，请留意来电！", {
                                time: 2000
                            });
                            setTimeout(function () {
                                $(".from_btn").attr("disabled", false);
                            }, 2000);
                        } else {
                            layer.msg("未知错误，请刷新页面后重试！", {
                                time: 2000
                            });
                        }
                    }
                });
            } else {
                layer.msg("未知错误，请刷新页面后重试！", {
                    time: 2000
                });
                return;
            }
        } else {
            layer.msg("您已提交过问题，请留意来电！", {
                time: 2000
            });
            return;
        }
    })
})